from rest_framework import serializers

from misaka.serializers.Serializers import NestedModelSerializer
from .models import FileModel, BlockFileModel, FileMeta


class ListFileModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = FileModel
        fields = ['id', 'filename']


class FileMetaSerializer(serializers.ModelSerializer):
    class Meta:
        model = FileMeta
        fields = ['file_description']


class BlockFileModelSerializer(NestedModelSerializer):
    file_meta = FileMetaSerializer(allow_null=True, required=False)

    class Meta:
        model = BlockFileModel
        exclude = ['create_time']
        nested_serializers = {
            'file_meta': FileMetaSerializer,
        }
